import take from '../../config/api/take' // 引入api接口管理文件
const app = getApp()
const dayjs = require("./dayjs");
var WxNotificationCenter = require("../../config/WxNotificationCenter");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    mysendlist: [],
    tomelist: [],
    alllist: [],
    wfklist: [],
    yfklist: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    this.loadData();
    var that = this
    WxNotificationCenter.addNotification('reloadtasklist', that.loadData, that)
  },
  loadData() {
    console.log('loadData');
    let vm = this;
    //加载列表
    //获取我发布的
    let userid = app.globalData.userInfo.id;
    take.tasklist({
      "pageNo": 1,
      "pageSize": 9999,
      "creater": userid
    }, function (res) {
      let list = res.data.data.records;
      list = list.map(res => {
        res.isme = true;
        return res;
      })
      vm.setData({
        mysendlist: list
      })
      vm.loadisme();
    })
  },
  // 获取指派给我的
  loadisme() {
    let vm = this;
    //加载列表
    //获取我发布的
    let userid = app.globalData.userInfo.id;
    take.tasklist({
      "pageNo": 1,
      "pageSize": 9999,
      "userId": userid
    }, function (res) {
      let list = res.data.data.records;
      list = list.map(res => {
        res.isme = false;
        return res;
      })
      // 整合数组
      let mysendlist = vm.data.mysendlist;
      let alllist = mysendlist.concat(list);
      // 按照 startTime 排序
      alllist.sort(function (a, b) {
        // startTime 转时间戳 并且-转换为/
        let aTime = new Date(a.startTime.replace(/-/g, "/")).getTime();
        let bTime = new Date(b.startTime.replace(/-/g, "/")).getTime();
        return bTime - aTime;
      })
      // 筛查出未完成的
      let wfklist = [];
      let yfklist = [];
      for (let i = 0; i < alllist.length; i++) {
        if (alllist[i].feekbackStatus * 1 == 0) {
          wfklist.push(alllist[i]);
        } else {
          yfklist.push(alllist[i]);
        }
      }
      vm.setData({
        tomelist: list,
        alllist: alllist,
        wfklist: wfklist,
        yfklist: yfklist
      })
    })
  },
  clicktoinfo(e){
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '../managementinfo/managementinfo?item=' + JSON.stringify(item),
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  clickadd() {
    wx.navigateTo({
      url: '../managementsend/managementsend',
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})